package com.shuorikeji.huohuo.ui.home;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bytedance.sdk.djx.DJXSdk;
import com.bytedance.sdk.djx.IDJXService;
import com.bytedance.sdk.djx.model.DJXDrama;
import com.bytedance.sdk.djx.model.DJXError;
import com.bytedance.sdk.djx.model.DJXOthers;
import com.google.android.material.imageview.ShapeableImageView;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.shuorikeji.huohuo.R;
import com.shuorikeji.huohuo.adapter.CsjDjAdapter;
import com.shuorikeji.huohuo.adapter.DjAdapter;
import com.shuorikeji.huohuo.adapter.Mh1Adapter;
import com.shuorikeji.huohuo.adapter.QlNewBookAdapter;
import com.shuorikeji.huohuo.adapter.TjBook2Adapter;
import com.shuorikeji.huohuo.adapter.TjBookAdapter;
import com.shuorikeji.huohuo.adapter.YouLikeAdapter;
import com.shuorikeji.huohuo.base.BasePresenterActivity;
import com.shuorikeji.huohuo.bean.AllBookMainBean;
import com.shuorikeji.huohuo.bean.BookDefaultTypeBean;
import com.shuorikeji.huohuo.bean.BookDetailInfoBean;
import com.shuorikeji.huohuo.bean.BookDetailInfoSubBean;
import com.shuorikeji.huohuo.bean.BookDetailInfoTempBean;
import com.shuorikeji.huohuo.bean.BookFlInfoBean;
import com.shuorikeji.huohuo.bean.BookFlMainBean;
import com.shuorikeji.huohuo.bean.CsjDjFlBean;
import com.shuorikeji.huohuo.bean.DjInfoBean;
import com.shuorikeji.huohuo.bean.DjMainBean;
import com.shuorikeji.huohuo.bean.DjTypeMainBean;
import com.shuorikeji.huohuo.bean.DjTypeSSubBean;
import com.shuorikeji.huohuo.bean.DjTypeSubBean;
import com.shuorikeji.huohuo.bean.HotTagInfoBean;
import com.shuorikeji.huohuo.bean.HotTagMainBean;
import com.shuorikeji.huohuo.bean.Mh1FlMainBean;
import com.shuorikeji.huohuo.bean.Mh1FlSubBean;
import com.shuorikeji.huohuo.bean.MhInfoBean;
import com.shuorikeji.huohuo.bean.MhInfoMainBean;
import com.shuorikeji.huohuo.bean.TjBookMainBean;
import com.shuorikeji.huohuo.callback.ClickCallBack;
import com.shuorikeji.huohuo.common.Constant;
import com.shuorikeji.huohuo.mvp.AllPresenter;
import com.shuorikeji.huohuo.ui.SearchActivity;
import com.shuorikeji.huohuo.ui.dj.DjXqActivity;
import com.shuorikeji.huohuo.ui.fl.TaskGcActivity;
import com.shuorikeji.huohuo.ui.me.MyActivity;
import com.shuorikeji.huohuo.ui.mh.MhDetailActivity;
import com.shuorikeji.huohuo.ui.mh.MhEverydayTjActivity;
import com.shuorikeji.huohuo.ui.sj.SjActivity;
import com.shuorikeji.huohuo.utils.BusinessUtils;
import com.shuorikeji.huohuo.utils.InitUtils;
import com.shuorikeji.huohuo.utils.JsonUtil;
import com.shuorikeji.huohuo.utils.SpacesItemDecoration;
import com.shuorikeji.huohuo.utils.ToastShowUtil;
import com.shuorikeji.huohuo.view.CustomHorizontalScrollView;
import com.shuorikeji.huohuo.view.GridDividerItemDecoration;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

public class HomeActivity extends BasePresenterActivity<AllPresenter> {
    @BindView(R.id.ll_xs_tab)
    LinearLayout llXsTab;
    @BindView(R.id.tv_xs_tab)
    TextView tvXsTab;
    @BindView(R.id.iv_xs_tab)
    View viewXsTab;
    @BindView(R.id.ll_mh_tab)
    LinearLayout llMhTab;
    @BindView(R.id.tv_mh_tab)
    TextView tvMhTab;
    @BindView(R.id.iv_mh_tab)
    View viewMhTab;
    @BindView(R.id.ll_kj_tab)
    LinearLayout llKjTab;
    @BindView(R.id.tv_kj_tab)
    TextView tvKjTab;
    @BindView(R.id.iv_kj_tab)
    View viewKjTab;
    @BindView(R.id.iv_search)
    ImageView ivSearch;
    @BindView(R.id.ll_xs_ui)
    LinearLayout llXsUi;
    @BindView(R.id.ll_xs_type)
    LinearLayout llXsType;
    @BindView(R.id.ll_xs_all_fl)
    LinearLayout llXsTjAllFl;
    @BindView(R.id.ll_xs_tj_ui)
    LinearLayout llXsTjUi;
    @BindView(R.id.ll_tj_type)
    LinearLayout llTjType;
    @BindView(R.id.tv_tj_more)
    TextView tvTjMore;
    @BindView(R.id.iv_tj_more)
    ImageView ivTjMore;
    @BindView(R.id.rv_tj_y_book)
    RecyclerView rvTj1Book;
    @BindView(R.id.rv_tj_e_book)
    RecyclerView rvTj2Book;
    @BindView(R.id.ll_tab_1)
    LinearLayout llTab1;
    @BindView(R.id.ll_tab_2)
    LinearLayout llTab2;
    @BindView(R.id.ll_tab_3)
    LinearLayout llTab3;
    @BindView(R.id.ll_tab_4)
    LinearLayout llTab4;
    @BindView(R.id.rl_cur_reading)
    RelativeLayout rlCurRead;
    @BindView(R.id.siv_book_fm)
    ShapeableImageView sicFm;
    @BindView(R.id.tv_book_name)
    TextView tvBookName;
    @BindView(R.id.tv_read_jl)
    TextView tvBookInfo;
    @BindView(R.id.tv_jx_read)
    TextView tvJxRead;
    @BindView(R.id.ll_mh_ui)
    LinearLayout llMhUi;
    @BindView(R.id.ll_mh_type)
    LinearLayout llMhType;
    @BindView(R.id.siv_1_mh)
    ShapeableImageView siv1Mh;
    @BindView(R.id.ll_mr_tj)
    LinearLayout llMrTj;
    @BindView(R.id.ll_mh_sd)
    LinearLayout llMhSd;
    @BindView(R.id.ll_mh_rank_bd)
    LinearLayout llMhRankBd;
    @BindView(R.id.ll_mh_fl)
    LinearLayout llMhFl;
    @BindView(R.id.tv_mh_type_title)
    TextView tvMhTypeTitle;
    @BindView(R.id.rv_mh)
    RecyclerView rvMh;
    @BindView(R.id.ll_mh_see_more)
    LinearLayout llMhSeeMore;
    @BindView(R.id.ll_mh_h)
    LinearLayout llMhH;
    @BindView(R.id.ll_kj_ui)
    LinearLayout llKjUi;
    @BindView(R.id.ll_xs_jx_ui)
    LinearLayout llXsJxUi;//小说精选UI
    @BindView(R.id.rv_c_you_like_book)
    RecyclerView rvCyouLike;
    @BindView(R.id.siv_1_jx_book_fm)
    ShapeableImageView siv1JxBookFm;
    @BindView(R.id.tv_jx_book_name)
    TextView tv1JxBookName;
    @BindView(R.id.tv_jx_book_score)
    TextView tv1JxBookScore;
    @BindView(R.id.tv_jx_book_desc)
    TextView tv1JxBookDesc;
    @BindView(R.id.tv_jx_book_tag)
    TextView tv1JxBookTag;
    @BindView(R.id.chsv_jx)
    CustomHorizontalScrollView chsvJxBook;
    @BindView(R.id.ll_jx_xs_2)
    LinearLayout ll2JxBook;
    @BindView(R.id.banner_jx_xs)
    Banner bnJxBook;
    @BindView(R.id.ll_jx_hot_tag_type)
    LinearLayout llHotTag;
    @BindView(R.id.rv_jx_hot_tag_book)
    RecyclerView rvHotTagBook;
    @BindView(R.id.ll_new_book_ui)
    LinearLayout llNewBookUi;//新上架UI
    @BindView(R.id.ll_new_book_h)
    LinearLayout llNewBookH;//换一换新书
    @BindView(R.id.rv_new_book)
    RecyclerView rvNewBook;//新书
    @BindView(R.id.rv_mh_jx)
    RecyclerView rvMhJx;
    @BindView(R.id.ll_mh_jx_see_more)
    LinearLayout llMhJxSeeMore;
    @BindView(R.id.ll_jx_mh_h)
    LinearLayout llMhJxH;
    @BindView(R.id.ll_dj_main_type)
    LinearLayout llDjMainType;//短剧主分类
    @BindView(R.id.ll_dj_sub_type)
    LinearLayout llDjSubType;//短剧子分类
    @BindView(R.id.srl_layout_dj)
    SmartRefreshLayout srlDj;
    @BindView(R.id.rv_data_dj)
    RecyclerView rvDj;
    @BindView(R.id.iv_close)
    ImageView ivClose;

    private List<BookDefaultTypeBean> bookTypeList = new ArrayList<>();//小说分类
    private List<BookFlInfoBean> tjBdTypeList = new ArrayList<>();//推荐榜单分类
    private int sFlChannelId;//推荐分类id
    private int tjBookPage = 1;
    private int tjBookPageSize = 5;
    private TjBookAdapter tjAdapter;
    private List<BookDetailInfoBean> tjBookList = new ArrayList<>();
    private List<BookDetailInfoBean> tjBook2PageList = new ArrayList<>();
    private TjBook2Adapter tjBook2Adapter;
    private List<BookDetailInfoTempBean> jxBookList = new ArrayList<>();//精选书籍
    private List<BookDetailInfoBean> yLikeBookList = new ArrayList<>();
    private YouLikeAdapter youLikeAdapter;
    private List<BookDetailInfoTempBean> bnJxBookList = new ArrayList<>();//轮播图书籍
    private List<HotTagInfoBean> hotTagList = new ArrayList<>();//热门标签
    private List<BookDetailInfoTempBean> hotTagBookList = new ArrayList<>();//热门标签书籍
    private QlNewBookAdapter hotTagBookAdapter;
    private List<BookDetailInfoTempBean> sfNewBookList = new ArrayList<>();//首发新书
    private QlNewBookAdapter newBookAdapter;
    private BookDetailInfoSubBean curReadingBookInfo;//当前正在读的书籍信息
    private List<Mh1FlSubBean> mh1FlList = new ArrayList<>();//漫画一级分类数据
    private int mh1FlId;//漫画一级分类id
    private int curMhPageSize;
    private int curMhPageNum;
    private int curJxMhPageSize;
    private int curJxMhPageNum;
    private List<MhInfoBean> mhList = new ArrayList<>();
    private MhInfoBean bannerMhInfo;
    private int totalMhCount;//漫画总数
    private int totalJxMhCount;//精选漫画总数
    private Mh1Adapter mh1Adapter;
    private List<MhInfoBean> jxMhList = new ArrayList<>();
    private Mh1Adapter jxMhAdapter;
    private List<DjTypeSubBean> djMainTypeList = new ArrayList<>();
    private List<DjTypeSSubBean> djSubTypeList = new ArrayList<>();
    private int curDjPage;
    private int djMainTypeId;
    private int djSubTypeId;
    private List<DjInfoBean> djList = new ArrayList<>();
    private DjAdapter djAdapter;
    private List<DJXDrama> csjDjList = new ArrayList<>();
    private CsjDjAdapter csjDjAdapter;
    private List<CsjDjFlBean> csjFlList = new ArrayList<>();
    private String curCsjDjFlName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getmImmersionBar().reset().statusBarColor(R.color.transparent).statusBarDarkFont(true, 0.2f).init();
    }

    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_home);
    }

    @Override
    protected void onResume() {
        super.onResume();
        curReadingBookInfo = BusinessUtils.getCurReadingBookInfo();
        if (curReadingBookInfo == null) {
            rlCurRead.setVisibility(View.GONE);
        } else {
            rlCurRead.setVisibility(View.VISIBLE);
            showCurReadingInfo();
        }
    }

    @Override
    protected void initData() {
        initSmartRefreshLayout();
        setTopUiShow(1);
        initAdapter();
        setBookTypeData();
        getCYouLike();
        initClick();
    }

    private void initSmartRefreshLayout() {
        srlDj.setRefreshHeader(new ClassicsHeader(HomeActivity.this));
        srlDj.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshLayout) {
                //刷新
                curDjPage = 1;
                //getDjList();
                getCsjDjList();
            }
        });
        srlDj.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                //加载更多
                curDjPage = curDjPage + 1;
                //getDjList();
                getCsjDjList();
            }
        });
    }

    private void showCurReadingInfo() {
        BusinessUtils.setLoadImg(HomeActivity.this, Constant.IMG_OSS_BASE_URL + curReadingBookInfo.getCover_image(), sicFm);
        tvBookName.setText(curReadingBookInfo.getName());
        tvBookInfo.setText(curReadingBookInfo.getChapter_num() + " " + curReadingBookInfo.getCurZjTitle());
    }

    /**
     * @param flag 1小说
     *             2漫画
     *             3看剧
     */
    private void setTopUiShow(int flag) {
        tvXsTab.setTextColor((flag == 1) ? getResources().getColor(R.color.color_333333) : getResources().getColor(R.color.color_999999));
        viewXsTab.setVisibility((flag == 1) ? View.VISIBLE : View.INVISIBLE);
        llXsUi.setVisibility((flag == 1) ? View.VISIBLE : View.GONE);

        tvMhTab.setTextColor((flag == 2) ? getResources().getColor(R.color.color_333333) : getResources().getColor(R.color.color_999999));
        viewMhTab.setVisibility((flag == 2) ? View.VISIBLE : View.INVISIBLE);
        llMhUi.setVisibility((flag == 2) ? View.VISIBLE : View.GONE);

        tvKjTab.setTextColor((flag == 3) ? getResources().getColor(R.color.color_333333) : getResources().getColor(R.color.color_999999));
        viewKjTab.setVisibility((flag == 3) ? View.VISIBLE : View.INVISIBLE);
        llKjUi.setVisibility((flag == 3) ? View.VISIBLE : View.GONE);
    }

    /**
     * 显示小说分类
     *
     * @param flag 1推荐
     *             2精选
     *             3新上架
     */
    private void setBookFlViewShow(int flag) {
        llXsTjUi.setVisibility((flag == 1) ? View.VISIBLE : View.GONE);
        llXsJxUi.setVisibility((flag == 2) ? View.VISIBLE : View.GONE);
        llNewBookUi.setVisibility((flag == 3) ? View.VISIBLE : View.GONE);
    }

    private void initAdapter() {
        rvTj1Book.setLayoutManager(new GridLayoutManager(this, 2, GridLayoutManager.VERTICAL, false));
        rvTj1Book.addItemDecoration(new GridDividerItemDecoration(60));
        tjAdapter = new TjBookAdapter(HomeActivity.this, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        BookDetailInfoBean data = (BookDetailInfoBean) object;
                        Intent intent = new Intent(HomeActivity.this, BookInfoActivity.class);
                        intent.putExtra("BOOK_ID", data.getId());
                        startActivity(intent);
                        break;
                }
            }
        });
        rvTj1Book.setAdapter(tjAdapter);

        rvTj2Book.setLayoutManager(new GridLayoutManager(this, 2, GridLayoutManager.VERTICAL, false));
        tjBook2Adapter = new TjBook2Adapter(HomeActivity.this, 1, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        BookDetailInfoBean data = (BookDetailInfoBean) object;
                        Intent intent = new Intent(HomeActivity.this, BookInfoActivity.class);
                        intent.putExtra("BOOK_ID", data.getId());
                        startActivity(intent);
                        break;
                }
            }
        });
        rvTj2Book.setAdapter(tjBook2Adapter);

        rvCyouLike.setLayoutManager(new LinearLayoutManager(HomeActivity.this, LinearLayoutManager.VERTICAL, false));
        rvCyouLike.addItemDecoration(new SpacesItemDecoration(0, 0, 10, 0));
        youLikeAdapter = new YouLikeAdapter(HomeActivity.this, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        BookDetailInfoBean data = (BookDetailInfoBean) object;
                        Intent intent = new Intent(HomeActivity.this, BookInfoActivity.class);
                        intent.putExtra("BOOK_ID", data.getId());
                        startActivity(intent);
                        break;
                }
            }
        });
        rvCyouLike.setAdapter(youLikeAdapter);

        rvHotTagBook.setLayoutManager(new GridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false));
        rvHotTagBook.addItemDecoration(new GridDividerItemDecoration(60));
        hotTagBookAdapter = new QlNewBookAdapter(HomeActivity.this, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        BookDetailInfoTempBean data = (BookDetailInfoTempBean) object;
                        Intent intent = new Intent(HomeActivity.this, BookInfoActivity.class);
                        intent.putExtra("BOOK_ID", data.getId());
                        startActivity(intent);
                        break;
                }
            }
        });
        rvHotTagBook.setAdapter(hotTagBookAdapter);

        rvNewBook.setLayoutManager(new GridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false));
        rvNewBook.addItemDecoration(new GridDividerItemDecoration(60));
        newBookAdapter = new QlNewBookAdapter(HomeActivity.this, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        BookDetailInfoTempBean data = (BookDetailInfoTempBean) object;
                        Intent intent = new Intent(HomeActivity.this, BookInfoActivity.class);
                        intent.putExtra("BOOK_ID", data.getId());
                        startActivity(intent);
                        break;
                }
            }
        });
        rvNewBook.setAdapter(newBookAdapter);

        rvMh.setLayoutManager(new GridLayoutManager(this, 3, GridLayoutManager.VERTICAL, false));
        rvMh.addItemDecoration(new GridDividerItemDecoration(60));
        mh1Adapter = new Mh1Adapter(HomeActivity.this, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        MhInfoBean data = (MhInfoBean) object;
                        Intent intent = new Intent(HomeActivity.this, MhDetailActivity.class);
                        intent.putExtra("MH_ID", data.getId());
                        startActivity(intent);
                        break;
                }
            }
        });
        rvMh.setAdapter(mh1Adapter);

        rvMhJx.setLayoutManager(new GridLayoutManager(this, 3, GridLayoutManager.VERTICAL, false));
        rvMhJx.addItemDecoration(new GridDividerItemDecoration(60));
        jxMhAdapter = new Mh1Adapter(HomeActivity.this, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        MhInfoBean data = (MhInfoBean) object;
                        Intent intent = new Intent(HomeActivity.this, MhDetailActivity.class);
                        intent.putExtra("MH_ID", data.getId());
                        startActivity(intent);
                        break;
                }
            }
        });
        rvMhJx.setAdapter(jxMhAdapter);

//        rvDj.setLayoutManager(new GridLayoutManager(this, 3, GridLayoutManager.VERTICAL, false));
//        rvDj.addItemDecoration(new GridDividerItemDecoration(60));
//        djAdapter = new DjAdapter(HomeActivity.this, new ClickCallBack() {
//            @Override
//            public void onClick(int flag, Object object) {
//                switch (flag) {
//                    case 1:
//                        DjInfoBean data = (DjInfoBean) object;
//                        Intent intent = new Intent(HomeActivity.this, DjDetailActivity.class);
//                        intent.putExtra("DJ_ID", data.getId());
//                        intent.putExtra("ALL_DJ", JsonUtil.toJson(djList));
//                        startActivity(intent);
//                        break;
//                }
//            }
//        });
//        rvDj.setAdapter(djAdapter);

        rvDj.setLayoutManager(new GridLayoutManager(this, 3, GridLayoutManager.VERTICAL, false));
        rvDj.addItemDecoration(new GridDividerItemDecoration(25));
        csjDjAdapter = new CsjDjAdapter(HomeActivity.this, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        DJXDrama data = (DJXDrama) object;
//                        Intent intent = new Intent(HomeActivity.this, DjDetailActivity.class);
//                        intent.putExtra("DJ_ID", data.id);
//                        intent.putExtra("ALL_DJ", JsonUtil.toJson(csjDjList));
//                        intent.putExtra("CSJ_INFO", JsonUtil.toJson(data));
//                        startActivity(intent);

                        Intent intent = new Intent(HomeActivity.this, DjXqActivity.class);
                        intent.putExtra("dramaId", data.id);
                        intent.putExtra("dramaBean", JsonUtil.toJson(data));
                        startActivity(intent);
                        break;
                }
            }
        });
        rvDj.setAdapter(csjDjAdapter);
    }

    /**
     * 小说分类
     */
    private void setBookTypeData() {
        bookTypeList.clear();

        BookDefaultTypeBean data1 = new BookDefaultTypeBean();
        data1.setSec(true);
        data1.setType("推荐");
        bookTypeList.add(data1);
        data1 = null;

        BookDefaultTypeBean data2 = new BookDefaultTypeBean();
        data2.setSec(false);
        data2.setType("精选");
        bookTypeList.add(data2);
        data2 = null;

        BookDefaultTypeBean data3 = new BookDefaultTypeBean();
        data3.setSec(false);
        data3.setType("新上架");
        bookTypeList.add(data3);
        data3 = null;

        BookDefaultTypeBean data4 = new BookDefaultTypeBean();
        data4.setSec(false);
        data4.setType("完结");
        bookTypeList.add(data4);
        data4 = null;

        setBookFlViewShow(1);
        showBookTypeView();
        getTjType();
    }

    /**
     * 显示小说分类
     */
    private void showBookTypeView() {
        llXsType.removeAllViews();
        for (int i = 0; i < bookTypeList.size(); i++) {
            View subView = View.inflate(HomeActivity.this, R.layout.home_top_xs_type_layout, null);
            subView.setPadding(0, 0, 40, 0);
            LinearLayout llMain = subView.findViewById(R.id.ll_main);
            TextView tvType = subView.findViewById(R.id.tv_type);
            tvType.setText(bookTypeList.get(i).getType());
            BusinessUtils.setTxtFold(tvType, bookTypeList.get(i).isSec());
            tvType.setBackground((bookTypeList.get(i).isSec()) ? getResources().getDrawable(R.drawable.shape_8_f9e141) : getResources().getDrawable(R.drawable.shape_8_ffffff));
            llMain.setId(i);
            llXsType.addView(subView);
            llMain.setOnClickListener(view -> {
                if (!"完结".equals(bookTypeList.get(llMain.getId()).getType())) {
                    for (int j = 0; j < bookTypeList.size(); j++) {
                        if (llMain.getId() == j) {
                            bookTypeList.get(j).setSec(true);
                        } else {
                            bookTypeList.get(j).setSec(false);
                        }
                    }
                    showBookTypeView();
                }
                switch (bookTypeList.get(llMain.getId()).getType()) {
                    case "推荐":
                        setBookFlViewShow(1);
                        getTjType();
                        break;
                    case "精选":
                        setBookFlViewShow(2);
                        getJxBook();
                        getBannerBook();
                        getHotTag();
                        break;
                    case "新上架":
                        setBookFlViewShow(3);
                        getNewBook();
                        break;
                    case "完结":
                        Intent intent = new Intent(HomeActivity.this, WjzxActivity.class);
                        startActivity(intent);
                        break;
                }
            });
        }
    }

    private void getTjType() {
        mPresenter.getSecFl(HomeActivity.this, 2, -1, true, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        BookFlMainBean data = (BookFlMainBean) object;
                        tjBdTypeList.clear();
                        tjBdTypeList.addAll(data.getData());
                        if (tjBdTypeList != null && tjBdTypeList.size() > 0) {
                            sFlChannelId = tjBdTypeList.get(0).getId();
                            for (int i = 0; i < tjBdTypeList.size(); i++) {
                                tjBdTypeList.get(i).setSec((i == 0) ? true : false);
                            }
                            getTjBook();
                            getTjSecPageBook();
                        }
                        showTjBdTypeView();
                        break;
                    case 2:
                        String msg = (String) object;
                        ToastShowUtil.showToastCenter(HomeActivity.this, msg);
                        break;
                }
            }
        });
    }

    /**
     * 显示推荐榜单
     */
    private void showTjBdTypeView() {
        llTjType.removeAllViews();
        for (int i = 0; i < tjBdTypeList.size(); i++) {
            View subView = View.inflate(HomeActivity.this, R.layout.tj_bd_type_layout, null);
            subView.setPadding(0, 0, 50, 0);
            LinearLayout llMain = subView.findViewById(R.id.ll_main);
            TextView tvType = subView.findViewById(R.id.tv_type);
            tvType.setText(tjBdTypeList.get(i).getName());
            BusinessUtils.setTxtFold(tvType, tjBdTypeList.get(i).isSec());
            tvType.setTextColor((tjBdTypeList.get(i).isSec()) ? getResources().getColor(R.color.color_333333) : getResources().getColor(R.color.color_999999));
            llMain.setId(i);
            llTjType.addView(subView);
            llMain.setOnClickListener(view -> {
                for (int j = 0; j < tjBdTypeList.size(); j++) {
                    if (llMain.getId() == j) {
                        tjBdTypeList.get(j).setSec(true);
                    } else {
                        tjBdTypeList.get(j).setSec(false);
                    }
                }
                sFlChannelId = tjBdTypeList.get(llMain.getId()).getId();
                showTjBdTypeView();
                getTjBook();
                getTjSecPageBook();
            });
        }
    }

    /**
     * 获取推荐书籍
     */
    private void getTjBook() {
        mPresenter.getTjBook(HomeActivity.this, tjBookPage, tjBookPageSize, sFlChannelId, true, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        TjBookMainBean data = (TjBookMainBean) object;
                        tjBookList.clear();
                        tjBookList.addAll(data.getData().getData());
                        tjAdapter.setData(tjBookList);
                        break;
                    case 2:
                        String msg = (String) object;
                        ToastShowUtil.showToastCenter(HomeActivity.this, msg);
                        break;
                }
            }
        });
    }

    /**
     * 获取推荐书籍 第二页数据
     */
    private void getTjSecPageBook() {
        mPresenter.getTjBook(HomeActivity.this, tjBookPage + 1, tjBookPageSize, sFlChannelId, true, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        TjBookMainBean data = (TjBookMainBean) object;
                        tjBook2PageList.clear();
                        tjBook2PageList.addAll(data.getData().getData());
                        tjBook2Adapter.setData(tjBook2PageList);
                        break;
                    case 2:
                        String msg = (String) object;
                        ToastShowUtil.showToastCenter(HomeActivity.this, msg);
                        break;
                }
            }
        });
    }

    /**
     * 精选书籍
     */
    private void getJxBook() {
        getAllBook(true, 4, 1, -1, -1, 1, -1, -1, -1, 0);
    }

    /**
     * 新书上架
     */
    private void getNewBook() {
        getAllBook(true, 3, 1, 2, -1, -1, -1, -1, -1, 0);
    }

    /**
     * 精选轮播
     */
    private void getBannerBook() {
        getAllBook(false, 5, 1, -1, -1, -1, 1, -1, -1, 0);
    }

    /**
     * 获取热门标签
     */
    private void getHotTag() {
        mPresenter.getHotTag(HomeActivity.this, true, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        HotTagMainBean data = (HotTagMainBean) object;
                        hotTagList.clear();
                        hotTagList.addAll(data.getData().getData());
                        if (hotTagList != null && hotTagList.size() > 0) {
                            for (int i = 0; i < hotTagList.size(); i++) {
                                if (i == 0) {
                                    hotTagList.get(i).setSec(true);
                                } else {
                                    hotTagList.get(i).setSec(false);
                                }
                            }
                            showHotTagView();
                            getAllBook(false, 7, 1, -1, -1, -1, -1, -2,
                                    hotTagList.get(0).getId(), 0);
                        }
                        break;
                    case 2:
                        String msg = (String) object;
                        ToastShowUtil.showToastCenter(HomeActivity.this, msg);
                        break;
                }
            }
        });
    }

    /**
     * 获取所有书籍
     *
     * @param flagTemp 1新书严选
     *                 2潜力新书
     *                 3新书首发
     *                 4精选
     *                 5banner
     *                 6完结甄选
     *                 7热门标签书籍
     *                 8会员书库
     *                 9大家都在看
     */
    private void getAllBook(boolean show, int flagTemp, int curPage, int sort, int score, int winnow, int banner, int completed, int tagId, int is_vip) {
        mPresenter.getAllBook(HomeActivity.this, flagTemp, sort, 20, curPage, "", -1,
                -1, -1, tagId, completed, is_vip, -1, score,
                winnow, banner, "", -1, show, new ClickCallBack() {
                    @Override
                    public void onClick(int flag, Object object) {
                        switch (flag) {
                            case 1:
                                AllBookMainBean data = (AllBookMainBean) object;
                                if (flagTemp == 3) {
                                    sfNewBookList.clear();
                                    sfNewBookList.addAll(data.getData().getData());
                                    newBookAdapter.setData(sfNewBookList);
                                } else if (flagTemp == 4) {
                                    jxBookList.clear();
                                    jxBookList.addAll(data.getData().getData());
                                    if (jxBookList != null && jxBookList.size() > 0) {
                                        show1JxBook(jxBookList.get(0));
                                        if (jxBookList.size() > 1) {
                                            chsvJxBook.setVisibility(View.VISIBLE);
                                            jxBookList.remove(0);
                                            show2JxBook();
                                        } else {
                                            chsvJxBook.setVisibility(View.GONE);
                                        }
                                    }
                                } else if (flagTemp == 5) {
                                    bnJxBookList.clear();
                                    bnJxBookList.addAll(data.getData().getData());
                                    setBannerBook();
                                } else if (flagTemp == 7) {
                                    hotTagBookList.clear();
                                    hotTagBookList.addAll(data.getData().getData());
                                    hotTagBookAdapter.setData(hotTagBookList);
                                }
                                break;
                            case 2:
                                String msg = (String) object;
                                ToastShowUtil.showToastCenter(HomeActivity.this, msg);
                        }
                    }
                });
    }

    /**
     * 猜你喜欢
     */
    private void getCYouLike() {
        mPresenter.cYouLike(HomeActivity.this, 1, 20, true, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        TjBookMainBean data = (TjBookMainBean) object;
                        yLikeBookList.clear();
                        yLikeBookList.addAll(data.getData().getData());
                        youLikeAdapter.setData(yLikeBookList);
                        break;
                    case 2:
                        String msg = (String) object;
                        ToastShowUtil.showToastCenter(HomeActivity.this, msg);
                        break;
                }
            }
        });
    }

    /**
     * 显示精选佳作的第一本书
     *
     * @param bookInfo 书籍信息
     */
    private void show1JxBook(BookDetailInfoTempBean bookInfo) {
        BusinessUtils.setLoadImg(HomeActivity.this, Constant.IMG_OSS_BASE_URL + bookInfo.getCover_image(), siv1JxBookFm);
        tv1JxBookName.setText(bookInfo.getName());
        tv1JxBookScore.setText(bookInfo.getScore() + "分");
        tv1JxBookDesc.setText(Html.fromHtml(bookInfo.getContent()));
        tv1JxBookTag.setText(BusinessUtils.getNewBookYxTag(bookInfo.getTag_id()));
    }

    /**
     * 精选佳作
     */
    private void show2JxBook() {
        ll2JxBook.removeAllViews();
        for (int i = 0; i < jxBookList.size(); i++) {
            View subView = View.inflate(HomeActivity.this, R.layout.tj_sy_book_item_layout, null);
            subView.setPadding(0, 0, 60, 0);
            LinearLayout llMain = subView.findViewById(R.id.ll_main);
            ShapeableImageView sivFm = subView.findViewById(R.id.siv_fm);
            TextView tvName = subView.findViewById(R.id.tv_name);
            TextView tvTag = subView.findViewById(R.id.tv_tag);
            BusinessUtils.setLoadImg(HomeActivity.this, Constant.IMG_OSS_BASE_URL + jxBookList.get(i).getCover_image(), sivFm);
            tvName.setText(jxBookList.get(i).getName());
            tvTag.setText(BusinessUtils.getNewBookYxTag(jxBookList.get(i).getTag_id()));
            llMain.setId(i);
            ll2JxBook.addView(subView);
            llMain.setOnClickListener(view -> {
                Intent intent = new Intent(HomeActivity.this, BookInfoActivity.class);
                intent.putExtra("BOOK_ID", jxBookList.get(llMain.getId()).getId());
                startActivity(intent);
            });
        }
    }

    /**
     * 设置轮播图书籍
     */
    private void setBannerBook() {
        bnJxBook.setAdapter(new BannerImageAdapter<BookDetailInfoTempBean>(bnJxBookList) {
            @Override
            public void onBindView(BannerImageHolder holder, BookDetailInfoTempBean data, int position, int size) {
                holder.imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                BusinessUtils.setLoadImg(HomeActivity.this, Constant.IMG_OSS_BASE_URL + data.getCover_image(), holder.imageView);
            }
        });
        bnJxBook.isAutoLoop(true);
        bnJxBook.setIndicator(new CircleIndicator(this));
        bnJxBook.setIndicatorSelectedColor(0xffffffff);
        bnJxBook.setIndicatorSpace(15);
        bnJxBook.start();
        bnJxBook.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(Object data, int position) {
                Log.i("wxl", "第" + position + "个轮播图");
                Intent intent = new Intent(HomeActivity.this, BookInfoActivity.class);
                intent.putExtra("BOOK_ID", bnJxBookList.get(position).getId());
                startActivity(intent);
            }
        });
    }

    /**
     * 热门标签view
     */
    private void showHotTagView() {
        llHotTag.removeAllViews();
        for (int i = 0; i < hotTagList.size(); i++) {
            View subView = View.inflate(HomeActivity.this, R.layout.hot_tag_item_layout, null);
            subView.setPadding(0, 0, 40, 0);
            LinearLayout llMain = subView.findViewById(R.id.ll_main);
            TextView tvTagName = subView.findViewById(R.id.tv_tag_name);
            tvTagName.setBackground((hotTagList.get(i).isSec()) ? getResources().getDrawable(R.drawable.shape_6_f9e141) :
                    getResources().getDrawable(R.drawable.shape_6_f2f2f2));
            tvTagName.setTextColor((hotTagList.get(i).isSec()) ? getResources().getColor(R.color.color_333333) :
                    getResources().getColor(R.color.color_666666));
            tvTagName.setText(hotTagList.get(i).getName());
            llMain.setId(i);
            llHotTag.addView(subView);
            llMain.setOnClickListener(view -> {
                for (int j = 0; j < hotTagList.size(); j++) {
                    if (llMain.getId() == j) {
                        hotTagList.get(j).setSec(true);
                    } else {
                        hotTagList.get(j).setSec(false);
                    }
                }
                showHotTagView();
                getAllBook(true, 7, 1, -1, -1, -1, -1, -2,
                        hotTagList.get(llMain.getId()).getId(), 0);
            });
        }
    }

    private void getMh1Fl() {
        mPresenter.getMh1Fl(false, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        Mh1FlMainBean data = (Mh1FlMainBean) object;
                        mh1FlList.clear();
                        mh1FlList.addAll(data.getData());
                        if (mh1FlList != null && mh1FlList.size() > 0) {
                            for (int i = 0; i < mh1FlList.size(); i++) {
                                mh1FlList.get(i).setSec((i == 0) ? true : false);
                            }
                            tvMhTypeTitle.setText(mh1FlList.get(0).getName());
                            mh1FlId = mh1FlList.get(0).getId();
                            curMhPageNum = 1;
                            curMhPageSize = 7;
                            getAllMh();
                        }
                        showMh1FlView();
                        break;
                    case 2:
                        String msg = (String) object;
                        ToastShowUtil.showToastCenter(HomeActivity.this, msg);
                        break;
                }
            }
        });
    }

    /**
     * 获取所有漫画
     */
    private void getAllMh() {
        mPresenter.getAllMh(1, -1, curMhPageSize, curMhPageNum, "", "", mh1FlId, -1, -1, -1,
                -1, -1, -1, -1, -1, -1, true, new ClickCallBack() {
                    @Override
                    public void onClick(int flag, Object object) {
                        switch (flag) {
                            case 1:
                                MhInfoMainBean data = (MhInfoMainBean) object;
                                mhList.clear();
                                mhList.addAll(data.getData().getData());
                                totalMhCount = data.getData().getTotal();
                                if (mhList != null && mhList.size() > 0) {
                                    siv1Mh.setVisibility(View.VISIBLE);
                                    show1PageMh(mhList.get(0));
                                    if (mhList.size() > 1) {
                                        mhList.remove(0);
                                        mh1Adapter.setData(mhList);
                                    }
                                } else {
                                    siv1Mh.setVisibility(View.GONE);
                                }
                                break;
                            case 2:
                                String msg = (String) object;
                                ToastShowUtil.showToastCenter(HomeActivity.this, msg);
                                break;
                        }
                    }
                });
    }

    /**
     * 显示横屏漫画
     *
     * @param data 漫画
     */
    private void show1PageMh(MhInfoBean data) {
        bannerMhInfo = data;
        BusinessUtils.setLoadImg(HomeActivity.this, Constant.IMG_OSS_BASE_URL + data.getCover_image(), siv1Mh);
    }

    /**
     * 获取精选漫画
     */
    private void getJxMh() {
        mPresenter.getJxMh(curJxMhPageSize, curJxMhPageNum, true, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        MhInfoMainBean data = (MhInfoMainBean) object;
                        jxMhList.clear();
                        jxMhList.addAll(data.getData().getData());
                        totalJxMhCount = data.getData().getTotal();
                        jxMhAdapter.setData(jxMhList);
                        break;
                    case 2:
                        String msg = (String) object;
                        ToastShowUtil.showToastCenter(HomeActivity.this, msg);
                        break;
                }
            }
        });
    }

    /**
     * 漫画一级分类view
     */
    private void showMh1FlView() {
        llMhType.removeAllViews();
        for (int i = 0; i < mh1FlList.size(); i++) {
            View subView = View.inflate(HomeActivity.this, R.layout.home_top_xs_type_layout, null);
            subView.setPadding(0, 0, 40, 0);
            LinearLayout llMain = subView.findViewById(R.id.ll_main);
            TextView tvType = subView.findViewById(R.id.tv_type);
            tvType.setText(mh1FlList.get(i).getName());
            BusinessUtils.setTxtFold(tvType, mh1FlList.get(i).isSec());
            tvType.setBackground((mh1FlList.get(i).isSec()) ? getResources().getDrawable(R.drawable.shape_8_f9e141) : getResources().getDrawable(R.drawable.shape_8_ffffff));
            llMain.setId(i);
            llMhType.addView(subView);
            llMain.setOnClickListener(view -> {
                for (int j = 0; j < mh1FlList.size(); j++) {
                    mh1FlList.get(j).setSec((llMain.getId() == j) ? true : false);
                }
                mh1FlId = mh1FlList.get(llMain.getId()).getId();
                curMhPageNum = 1;
                tvMhTypeTitle.setText(mh1FlList.get(llMain.getId()).getName());
                getAllMh();
                showMh1FlView();
            });
        }
    }

    /**
     * 短剧分类
     */
    private void getDjTypeTree() {
        mPresenter.djTypeTree(true, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        DjTypeMainBean data = (DjTypeMainBean) object;
                        djMainTypeList.clear();
                        djMainTypeList.addAll(data.getData());
                        if (djMainTypeList != null && djMainTypeList.size() > 0) {
                            for (int i = 0; i < djMainTypeList.size(); i++) {
                                if (i == 0) {
                                    djMainTypeList.get(i).setSec(true);
                                } else {
                                    djMainTypeList.get(i).setSec(false);
                                }
                            }
                            djMainTypeId = djMainTypeList.get(0).getId();
                            showDjFlView();
                            djSubTypeList.clear();
                            djSubTypeList.addAll(djMainTypeList.get(0).getChild_data());
                            if (djSubTypeList != null && djSubTypeList.size() > 0) {
                                for (int j = 0; j < djSubTypeList.size(); j++) {
                                    if (j == 0) {
                                        djSubTypeList.get(j).setSec(true);
                                    } else {
                                        djSubTypeList.get(j).setSec(false);
                                    }
                                }
                                djSubTypeId = djSubTypeList.get(0).getId();
                                showDjSubFlView();
                                curDjPage = 1;
                                getDjList();
                            }
                        }
                        break;
                    case 2:
                        String msg = (String) object;
                        ToastShowUtil.showToastCenter(HomeActivity.this, msg);
                        break;
                }
            }
        });
    }

    /**
     * 短剧二级分类view
     */
    private void showDjSubFlView() {
        llDjSubType.removeAllViews();
        for (int i = 0; i < djSubTypeList.size(); i++) {
            View subView = View.inflate(HomeActivity.this, R.layout.dj_sub_type_item_layout, null);
            subView.setPadding(0, 0, 40, 0);
            LinearLayout llMain = subView.findViewById(R.id.ll_main);
            TextView tvType = subView.findViewById(R.id.tv_type);
            tvType.setText(djSubTypeList.get(i).getName());
            BusinessUtils.setTxtFold(tvType, djSubTypeList.get(i).isSec());
            tvType.setTextColor((djSubTypeList.get(i).isSec()) ? getResources().getColor(R.color.white_color) : getResources().getColor(R.color.color_999999));
            tvType.setBackground((djSubTypeList.get(i).isSec()) ? getResources().getDrawable(R.drawable.shape_12_ff7200) : getResources().getDrawable(R.drawable.shape_12_ffffff));
            llMain.setId(i);
            llDjSubType.addView(subView);
            llMain.setOnClickListener(view -> {
                djSubTypeId = djSubTypeList.get(llMain.getId()).getId();
                for (int j = 0; j < djSubTypeList.size(); j++) {
                    if (j == llMain.getId()) {
                        djSubTypeList.get(j).setSec(true);
                    } else {
                        djSubTypeList.get(j).setSec(false);
                    }
                }
                showDjSubFlView();
                getDjList();
            });
        }
    }

    /**
     * 短剧一级分类view
     */
    private void showDjFlView() {
        llDjMainType.removeAllViews();
        for (int i = 0; i < djMainTypeList.size(); i++) {
            View subView = View.inflate(HomeActivity.this, R.layout.home_top_xs_type_layout, null);
            subView.setPadding(0, 0, 40, 0);
            LinearLayout llMain = subView.findViewById(R.id.ll_main);
            TextView tvType = subView.findViewById(R.id.tv_type);
            tvType.setText(djMainTypeList.get(i).getName());
            BusinessUtils.setTxtFold(tvType, djMainTypeList.get(i).isSec());
            tvType.setBackground((djMainTypeList.get(i).isSec()) ? getResources().getDrawable(R.drawable.shape_8_f9e141) : getResources().getDrawable(R.drawable.shape_8_ffffff));
            llMain.setId(i);
            llDjMainType.addView(subView);
            llMain.setOnClickListener(view -> {
                for (int j = 0; j < djMainTypeList.size(); j++) {
                    if (j == llMain.getId()) {
                        djMainTypeList.get(j).setSec(true);
                    } else {
                        djMainTypeList.get(j).setSec(false);
                    }
                }
                djMainTypeId = djMainTypeList.get(llMain.getId()).getId();
                showDjFlView();
                djSubTypeList.clear();
                djSubTypeList.addAll(djMainTypeList.get(llMain.getId()).getChild_data());
                if (djSubTypeList != null && djSubTypeList.size() > 0) {
                    for (int j = 0; j < djSubTypeList.size(); j++) {
                        if (j == 0) {
                            djSubTypeList.get(j).setSec(true);
                        } else {
                            djSubTypeList.get(j).setSec(false);
                        }
                    }
                    djSubTypeId = djSubTypeList.get(0).getId();
                    showDjSubFlView();
                    getDjList();
                }
            });
        }
    }

    private void getDjList() {
        mPresenter.djList(true, curDjPage, 20, djMainTypeId, djSubTypeId, "", "", 0, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        srlDj.finishRefresh();
                        srlDj.finishLoadMore();
                        DjMainBean data = (DjMainBean) object;
                        if (curDjPage == 1) {
                            djList.clear();
                        }
                        djList.addAll(data.getData().getData());
                        djAdapter.setData(djList);
                        break;
                    case 2:
                        srlDj.finishRefresh();
                        srlDj.finishLoadMore();
                        String msg = (String) object;
                        ToastShowUtil.showToastCenter(HomeActivity.this, msg);
                        break;
                }
            }
        });
    }

    private void getCsjDjFl() {
        try {
            InitUtils.checkShortDrama(new InitUtils.CheckCallback() {
                @Override
                public void success() {
                    DJXSdk.service().requestDramaCategoryList(new IDJXService.IDJXCallback<List<String>>() {
                        @Override
                        public void onSuccess(List<String> strings, @Nullable DJXOthers djxOthers) {
                            if (strings != null && strings.size() > 0) {
                                csjFlList.clear();
                                for (int i = 0; i < strings.size(); i++) {
                                    CsjDjFlBean data = new CsjDjFlBean();
                                    data.setName(strings.get(i));
                                    data.setSec((i == 0) ? true : false);
                                    csjFlList.add(data);
                                    data = null;
                                }
                                curCsjDjFlName = strings.get(0);
                                curDjPage = 1;
                                getCsjDjList();
                                showCsjDjFlView();
                            } else {
                                ToastShowUtil.showToastCenter(HomeActivity.this, "暂无数据");
                            }
                        }

                        @Override
                        public void onError(@NonNull DJXError djxError) {
                            ToastShowUtil.showToastCenter(HomeActivity.this, "短剧分类请求失败");
                        }
                    });
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void showCsjDjFlView() {
        llDjMainType.removeAllViews();
        for (int i = 0; i < csjFlList.size(); i++) {
            View subView = View.inflate(HomeActivity.this, R.layout.home_top_xs_type_layout, null);
            subView.setPadding(0, 0, 40, 0);
            LinearLayout llMain = subView.findViewById(R.id.ll_main);
            TextView tvType = subView.findViewById(R.id.tv_type);
            tvType.setText(csjFlList.get(i).getName());
            BusinessUtils.setTxtFold(tvType, csjFlList.get(i).isSec());
            tvType.setBackground((csjFlList.get(i).isSec()) ? getResources().getDrawable(R.drawable.shape_8_f9e141) : getResources().getDrawable(R.drawable.shape_8_ffffff));
            llMain.setId(i);
            llDjMainType.addView(subView);
            llMain.setOnClickListener(view -> {
                for (int j = 0; j < csjFlList.size(); j++) {
                    if (j == llMain.getId()) {
                        csjFlList.get(j).setSec(true);
                    } else {
                        csjFlList.get(j).setSec(false);
                    }
                }
                curCsjDjFlName = csjFlList.get(llMain.getId()).getName();
                curDjPage = 1;
                getCsjDjList();
                showCsjDjFlView();
            });
        }
    }

    private void getCsjDjList() {
        try {
            InitUtils.checkShortDrama(new InitUtils.CheckCallback() {
                @Override
                public void success() {
                    DJXSdk.service().requestDramaByCategory(curCsjDjFlName, curDjPage, 20, 1, new IDJXService.IDJXCallback<List<? extends DJXDrama>>() {
                        @Override
                        public void onSuccess(List<? extends DJXDrama> djxDramas, @Nullable DJXOthers djxOthers) {
                            srlDj.finishRefresh();
                            srlDj.finishLoadMore();
                            if (curDjPage == 1) {
                                csjDjList.clear();
                            }
                            csjDjList.addAll(djxDramas);
                            csjDjAdapter.setData(csjDjList);
                        }

                        @Override
                        public void onError(@NonNull DJXError djxError) {
                            srlDj.finishRefresh();
                            srlDj.finishLoadMore();
                            ToastShowUtil.showToastCenter(HomeActivity.this, "短剧请求失败");
                        }
                    });
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * @param tag 1普通
     *            2精选
     */
    private void mhCnLike(int tag) {
        mPresenter.mhCnLike(true, 1, 50, new ClickCallBack() {
            @Override
            public void onClick(int flag, Object object) {
                switch (flag) {
                    case 1:
                        MhInfoMainBean data = (MhInfoMainBean) object;
                        if (tag == 1) {
                            mhList.clear();
                            mhList.addAll(data.getData().getData());
                            totalMhCount = data.getData().getTotal();
                            if (mhList != null && mhList.size() > 0) {
                                siv1Mh.setVisibility(View.VISIBLE);
                                show1PageMh(mhList.get(0));
                                if (mhList.size() > 1) {
                                    mhList.remove(0);
                                    mh1Adapter.setData(mhList);
                                }
                            } else {
                                siv1Mh.setVisibility(View.GONE);
                            }
                        } else {
                            jxMhList.clear();
                            jxMhList.addAll(data.getData().getData());
                            totalJxMhCount = data.getData().getTotal();
                            jxMhAdapter.setData(jxMhList);
                        }
                        break;
                    case 2:
                        String msg = (String) object;
                        ToastShowUtil.showToastCenter(HomeActivity.this, msg);
                        break;
                }
            }
        });
    }

    private void initClick() {
        ivClose.setOnClickListener(view -> {
            rlCurRead.setVisibility(View.GONE);
        });
        llXsTab.setOnClickListener(view -> {
            setTopUiShow(1);
            setBookTypeData();
            getCYouLike();
        });
        llMhTab.setOnClickListener(view -> {
            curJxMhPageSize = 6;
            curJxMhPageNum = 1;
            setTopUiShow(2);
            getMh1Fl();
            getJxMh();
        });
        llKjTab.setOnClickListener(view -> {
            setTopUiShow(3);
            //getDjTypeTree();
            getCsjDjFl();
        });
        ivSearch.setOnClickListener(view -> {
            Intent intent = new Intent(HomeActivity.this, SearchActivity.class);
            startActivity(intent);
        });
        llXsTjAllFl.setOnClickListener(view -> {
            //小说-推荐-全部分类
            Intent intent = new Intent(HomeActivity.this, BookAllTypeActivity.class);
            startActivity(intent);
        });
        llMhSd.setOnClickListener(view -> {
            Intent intent = new Intent(HomeActivity.this, MhSdGcActivity.class);
            startActivity(intent);
        });
        llMhRankBd.setOnClickListener(view -> {
            Intent intent = new Intent(HomeActivity.this, MhRankActivity.class);
            startActivity(intent);
        });
        llMhFl.setOnClickListener(view -> {
            Intent intent = new Intent(HomeActivity.this, MhTypeActivity.class);
            startActivity(intent);
        });
        llMhSeeMore.setOnClickListener(view -> {
            Intent intent = new Intent(HomeActivity.this, MhTypeActivity.class);
            startActivity(intent);
        });
        llMhH.setOnClickListener(view -> {
            mhCnLike(1);
        });
        llMhJxSeeMore.setOnClickListener(view -> {
            Intent intent = new Intent(HomeActivity.this, MhTypeActivity.class);
            startActivity(intent);
        });
        llMhJxH.setOnClickListener(view -> {
            mhCnLike(2);
        });
        tvTjMore.setOnClickListener(view -> {
            //小说-推荐-更多榜单
            Intent intent = new Intent(HomeActivity.this, MoreBdActivity.class);
            startActivity(intent);
        });
        ivTjMore.setOnClickListener(view -> {
            //小说-推荐-更多榜单
            Intent intent = new Intent(HomeActivity.this, MoreBdActivity.class);
            startActivity(intent);
        });
        llTab2.setOnClickListener(view -> {
            Intent intent = new Intent(HomeActivity.this, SjActivity.class);
            startActivity(intent);
            finish();
        });
        llTab3.setOnClickListener(view -> {
            Intent intent = new Intent(HomeActivity.this, TaskGcActivity.class);
            startActivity(intent);
            finish();
        });
        llTab4.setOnClickListener(view -> {
            Intent intent = new Intent(HomeActivity.this, MyActivity.class);
            startActivity(intent);
            finish();
        });
        tvJxRead.setOnClickListener(view -> {
            Intent intent = new Intent(HomeActivity.this, BookDetailActivity.class);
            intent.putExtra("BOOK_ID", curReadingBookInfo.getId());
            startActivity(intent);
        });
        siv1Mh.setOnClickListener(view -> {
            if (bannerMhInfo != null) {
                Intent intent = new Intent(HomeActivity.this, MhDetailActivity.class);
                intent.putExtra("MH_ID", bannerMhInfo.getId());
                startActivity(intent);
            }
        });
        llMrTj.setOnClickListener(view -> {
            Intent intent = new Intent(HomeActivity.this, MhEverydayTjActivity.class);
            startActivity(intent);
        });
    }
}